<template>
  <div class="login_container">
    <el-row>
      <el-col :span="12" :xs="0"></el-col>
      <el-col :span="12" :xs="24">
        <div class="login_form">
          <el-form :model="login_data" ref="login_ref" :rules="login_rules">
            <el-form-item>
              <div style="color: #fff;font-weight:700;font-size:28px;margin:auto;margin-bottom:20px">用户登录</div>
            </el-form-item>
            <el-form-item prop="loginName">
              <el-input v-model="login_data.loginName" placeholder="请输入账号" :prefix-icon="User" clearable />
            </el-form-item>
            <el-form-item style="margin-bottom: 5px;" prop="password2">
              <el-input v-model="login_data.password2" type="password" placeholder="请输入密码" :prefix-icon="Lock" clearable
                show-password /> </el-form-item>
          </el-form>

          <el-button size="large" style="margin-top: 20px; width:100%;font-weight:700;margin-bottom:10px" type="primary"
            @click="login_btn(login_ref)">登录</el-button>

        </div>
      </el-col>
    </el-row>
    <div style="position: fixed;top:97vh;left:1vw"><a style=" text-decoration: none;color:#23527c;font-size:12px"
        href="http://webscan.360.cn/index/checkwebsite/url/www.kmlcp.com"
        name="1dc615b5801bddff07811cbadd4d4e83">360网站安全检测平台</a></div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { Iphone, Lock, User } from '@element-plus/icons-vue'
import loginStore from '@/store/login/index.js'
const $loginStore = loginStore()
import { useRouter, useRoute } from 'vue-router'
const $useRouter = useRouter()
const $useRoute = useRoute()
import loginStore2 from '@/store/main/index.js'
const $loginStore2 = loginStore2()
import { ElNotification } from 'element-plus'
import { getTime } from '@/utils/time.js'
import { MD5 } from 'crypto-js';
//#region 登陆
const login_data = reactive({
  loginName: '',
  password: '',
  password2: '',
})

const login_btn = (login_ref) => {
  if (!login_ref) return
  login_ref.validate(async (valid, fields) => {
    if (valid) {

      try {
        login_data.password = MD5(login_data.password2).toString();
        $loginStore2.router_list = [{
          meta: {
            title: "信息概览",
            hidden: false, // 路由是否隐藏：true隐藏，false显示
            icon: "ChatLineSquare",
            keepAlive: true,
          },
          path: '/information_overview',
          name: "information_overview", // 命名路由
        }]
        $loginStore2.router_name = {}
      
        await $loginStore.userLogin(login_data)
        if ($useRoute.query.redirect) {
          $useRouter.push($useRoute.query.redirect)
        } else {
          $useRouter.push('/information_overview')
        }


        ElNotification({
          type: 'success',
          message: '欢迎回来',
          title: `HI,${getTime()}好`,
        })
      } catch (error) {
        ElNotification({
          type: "error",
          message: '密码账号错误',
        })
      }

    } else {
      console.log('登录表单验证不通过!', fields)
    }
  })

}

const login_ref = ref()

const login_rules = reactive({
  loginName: [
    { required: true, message: '请输入账号', trigger: 'change' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'change' },
  ],
})

//#endregion


</script>

<style scoped lang='scss'>
.login_container {
  width: 100%;
  height: 100vh;
  background-image: url('@/assets/images/login-bg-1.jpg');
  background-size: cover;

  .login_form {
    position: relative;
    width: 45%;
    top: 28vh;
    left: 20vw;
    padding: 40px 40px 20px 40px;
    border-radius: 10px;
    background-color: #7A797B;
    animation: move 1s both;
  }
}

@keyframes move {
  0% {
    transform: translateX(0);
  }

  /* 初始位置为原点 */
  100% {
    transform: translateX(-20vw);
  }

  /* 最终位置向右移动200像素 */
}

a:hover {
  text-decoration: underline;
  color: red;
}
</style>
